package com.cr.business.controller;

import com.cr.business.domain.dto.QualifiedCertReqDto;
import com.cr.business.domain.vo.QualifiedCertDataVo;
import com.cr.business.service.ITbQualifiedCertInfoService;
import com.cr.common.annotation.Log;
import com.cr.common.core.controller.BaseController;
import com.cr.common.core.domain.AjaxResult;
import com.cr.common.core.page.TableDataInfo;
import com.cr.common.enums.BusinessType;
import com.cr.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 合格证信息Controller
 * 
 * @author tang
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/qualifiedCert/info")
public class TbQualifiedCertInfoController extends BaseController
{
    @Resource
    private ITbQualifiedCertInfoService tbQualifiedCertInfoService;

    /**
     * 查询合格证信息列表
     */
    @PreAuthorize("@ss.hasPermi('qualifiedCert:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(QualifiedCertReqDto dto)
    {
        startPage();
        List<QualifiedCertDataVo> list = tbQualifiedCertInfoService.selectTbQualifiedCertInfoList(dto);
        return getDataTable(list);
    }

    /**
     * 导出合格证信息列表
     */
    @PreAuthorize("@ss.hasPermi('qualifiedCert:info:export')")
    @Log(title = "合格证信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QualifiedCertReqDto dto)
    {
        List<QualifiedCertDataVo> list = tbQualifiedCertInfoService.selectTbQualifiedCertInfoList(dto);
        ExcelUtil<QualifiedCertDataVo> util = new ExcelUtil<>(QualifiedCertDataVo.class);
        util.exportExcel(response, list, "合格证信息数据");
    }

    /**
     * 获取合格证信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('qualifiedCert:info:query')")
    @GetMapping(value = "/{certId}")
    public AjaxResult getInfo(@PathVariable("certId") String certId)
    {
        return success(tbQualifiedCertInfoService.selectTbQualifiedCertInfoByCertId(certId));
    }

    /**
     * 删除合格证信息
     */
    @PreAuthorize("@ss.hasPermi('qualifiedCert:info:remove')")
    @Log(title = "合格证信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{certIds}")
    public AjaxResult remove(@PathVariable String[] certIds)
    {
        return toAjax(tbQualifiedCertInfoService.deleteTbQualifiedCertInfoByCertIds(certIds));
    }
}
